from model import Model, Dao
from model.user import UserDao 

class Project(Model):
    def __init__(self, _dict):
        """Arguments:
            parent_id --- int type, 0 means root
        """
        Model.__init__(self, _dict)
        
        self.name = _dict['name']
        self.description = _dict['description']
        self.created = _dict['created']
        
        # plan start date and end date
        self.start = _dict['start-date']
        self.end = _dict['end-date']
        
        # Associate field
        self.owner_id = _dict['owner_id']
    
    def get_owner(self):
        dao = UserDao()
        return dao.find_one({'_id': self.owner_id})

    def __repr__(self):
        return '<Project %r>' % (self.name)

class ProjectDao(Dao):
    def __init__(self):
        Dao.__init__(self, Project)
        self.collection = 'projects'
